using System.Collections;
using System.Collections.Generic;
using MEC;
using UnityEngine;
using YooAsset;

public class SceneManager : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    public void OpenScene(string _sceneName)
    {
        Timing.RunCoroutine(SceneLoadWithTween(_sceneName));
    }

    // 场景切换动画实验
    private IEnumerator<float> SceneLoadWithTween(string _sceneName)
    {

        var _uiAnimprefab = Resources.Load(Defines.UILoadingTweenPath);//部分ui界面动画的预制体;//部分ui界面动画的预制体
        GameObject _uiAnimObj = null;

        GameObject _uiAnimCanvas = GameObject.FindWithTag("LoadCanvas");
        _uiAnimObj = MonoBehaviour.Instantiate(_uiAnimprefab, _uiAnimCanvas.transform) as GameObject;
        
        yield return Timing.WaitUntilTrue(() => _uiAnimObj != null);
        _uiAnimObj.transform.localPosition = Vector3.zero;

        yield return Timing.WaitUntilTrue(() => (_uiAnimObj.GetComponent<UITransitionTween>().isLoadinDone));

        //加载出动画以后再跳转，不然可能会有不同步问题
        SceneHandle sceneHandle = YooAssets.LoadSceneAsync(_sceneName);

        sceneHandle.Completed += (SceneHandle _handle) =>
        {
            if (_handle.Status == EOperationStatus.Succeed)
            {
                UILoadEventDefines.SendUILoadMessage();

            }
        };
    }
}
